<html>
<head><meta charset="utf-8"><title>&#x27;rustc&#x27; panicked at &#x27;called Option::unwrap() on a None value · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/&#x27;rustc&#x27;.20panicked.20at.20&#x27;called.20Option.3A.3Aunwrap().20on.20a.20None.20value.html">&#x27;rustc&#x27; panicked at &#x27;called Option::unwrap() on a None value</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="248724617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/%27rustc%27%20panicked%20at%20%27called%20Option%3A%3Aunwrap%28%29%20on%20a%20None%20value/near/248724617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> antoyo <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/&#x27;rustc&#x27;.20panicked.20at.20&#x27;called.20Option.3A.3Aunwrap().20on.20a.20None.20value.html#248724617">(Aug 07 2021 at 16:44)</a>:</h4>
<p>Hi.<br>
As part of my work on the gcc codegen, I got to the point where I seem to produce invalid <code>.so</code> files for proc-macros as I get the following error when trying to load them:</p>
<div class="codehilite"><pre><span></span><code>thread &#39;rustc&#39; panicked at &#39;called `Option::unwrap()` on a `None` value&#39;, compiler/rustc_metadata/src/rmeta/decoder.rs:675:31
stack backtrace:
   0: rust_begin_unwind
             at /rustc/b41936b92cd8463020207cb2f62a4247942ef2e4/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/b41936b92cd8463020207cb2f62a4247942ef2e4/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/b41936b92cd8463020207cb2f62a4247942ef2e4/library/core/src/panicking.rs:50:5
   3: rustc_metadata::rmeta::decoder::&lt;impl rustc_metadata::creader::CrateMetadataRef&gt;::raw_proc_macro
   4: rustc_metadata::rmeta::decoder::cstore_impl::&lt;impl rustc_metadata::creader::CStore&gt;::item_children_untracked
   5: rustc_resolve::Resolver::resolutions
   6: rustc_resolve::imports::&lt;impl rustc_resolve::Resolver&gt;::resolve_ident_in_module_unadjusted_ext
   7: rustc_resolve::Resolver::resolve_ident_in_module_ext
   8: rustc_resolve::imports::ImportResolver::resolve_import::{{closure}}
   9: rustc_resolve::imports::ImportResolver::resolve_imports
  10: rustc_resolve::macros::&lt;impl rustc_expand::base::ResolverExpand for rustc_resolve::Resolver&gt;::resolve_imports
  11: rustc_expand::expand::MacroExpander::fully_expand_fragment
  12: rustc_expand::expand::MacroExpander::expand_crate
  13: rustc_session::utils::&lt;impl rustc_session::session::Session&gt;::time
  14: rustc_interface::passes::configure_and_expand
  15: rustc_interface::queries::Queries::expansion
  16: rustc_interface::queries::&lt;impl rustc_interface::interface::Compiler&gt;::enter
  17: rustc_span::with_source_map
  18: rustc_interface::interface::create_compiler_and_run
  19: scoped_tls::ScopedKey&lt;T&gt;::set
</code></pre></div>
<p><a href="https://github.com/rust-lang/rust/blob/41c1f39fa8317fc16779ceda7536fe93f1c89c34/compiler/rustc_metadata/src/rmeta/decoder.rs#L675">This is the code where it panics.</a></p>
<p>I tried loading the <code>.so</code> in the LLVM-based rustc and it cannot load it either. And loading in the gcc-based rustc a <code>.so</code> generated by LLVM works, so I assume my gcc codegen produces wrong <code>.so</code> for proc-macros.</p>
<p>Maybe the metadata is wrong.</p>
<p>I'm not sure what's the best way to look at metadata so I used <code>objcopy</code> and here's the result:</p>
<p>GCC metadata<br>
<a href="/user_uploads/4715/vWjlDNS16zC07l0x3-1BPY3Q/metadata_gcc.png">metadata_gcc.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/vWjlDNS16zC07l0x3-1BPY3Q/metadata_gcc.png" title="metadata_gcc.png"><img src="/user_uploads/4715/vWjlDNS16zC07l0x3-1BPY3Q/metadata_gcc.png"></a></div><p>LLVM metadata<br>
<a href="/user_uploads/4715/gneyJxfuRftum349CMw3yeVO/metadata_llvm.png">metadata_llvm.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/gneyJxfuRftum349CMw3yeVO/metadata_llvm.png" title="metadata_llvm.png"><img src="/user_uploads/4715/gneyJxfuRftum349CMw3yeVO/metadata_llvm.png"></a></div><p>The results look different because I had to use a different command for LLVM which is why it has some extra stuff at the beginning.</p>
<p>Any way on what could be the issue or how to debug this?</p>
<p>Thanks!</p>



<a name="248724809"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/%27rustc%27%20panicked%20at%20%27called%20Option%3A%3Aunwrap%28%29%20on%20a%20None%20value/near/248724809" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/&#x27;rustc&#x27;.20panicked.20at.20&#x27;called.20Option.3A.3Aunwrap().20on.20a.20None.20value.html#248724809">(Aug 07 2021 at 16:48)</a>:</h4>
<p>What is the code you use to create the metadata object file?</p>



<a name="248724901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/%27rustc%27%20panicked%20at%20%27called%20Option%3A%3Aunwrap%28%29%20on%20a%20None%20value/near/248724901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/&#x27;rustc&#x27;.20panicked.20at.20&#x27;called.20Option.3A.3Aunwrap().20on.20a.20None.20value.html#248724901">(Aug 07 2021 at 16:50)</a>:</h4>
<p><span class="user-mention" data-user-id="404242">@antoyo</span></p>



<a name="248724994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/%27rustc%27%20panicked%20at%20%27called%20Option%3A%3Aunwrap%28%29%20on%20a%20None%20value/near/248724994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/&#x27;rustc&#x27;.20panicked.20at.20&#x27;called.20Option.3A.3Aunwrap().20on.20a.20None.20value.html#248724994">(Aug 07 2021 at 16:53)</a>:</h4>
<p>Is it the code on the master branch?</p>



<a name="248725231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/%27rustc%27%20panicked%20at%20%27called%20Option%3A%3Aunwrap%28%29%20on%20a%20None%20value/near/248725231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> antoyo <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/&#x27;rustc&#x27;.20panicked.20at.20&#x27;called.20Option.3A.3Aunwrap().20on.20a.20None.20value.html#248725231">(Aug 07 2021 at 16:58)</a>:</h4>
<p>Yes, <a href="https://github.com/antoyo/rustc_codegen_gcc/blob/master/src/base.rs#L138">here</a></p>



<a name="248725306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/%27rustc%27%20panicked%20at%20%27called%20Option%3A%3Aunwrap%28%29%20on%20a%20None%20value/near/248725306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/&#x27;rustc&#x27;.20panicked.20at.20&#x27;called.20Option.3A.3Aunwrap().20on.20a.20None.20value.html#248725306">(Aug 07 2021 at 17:00)</a>:</h4>
<p>Could you do <code>readelf --hex-dump .rustc /path/to/proc-macro.so</code> on both proc-macros? What is the result? Are there any differences?</p>



<a name="248725729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/%27rustc%27%20panicked%20at%20%27called%20Option%3A%3Aunwrap%28%29%20on%20a%20None%20value/near/248725729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/&#x27;rustc&#x27;.20panicked.20at.20&#x27;called.20Option.3A.3Aunwrap().20on.20a.20None.20value.html#248725729">(Aug 07 2021 at 17:09)</a>:</h4>
<p>I'm wondering if the metadata is getting corrupted somehow - it shouldn't be possible to have <code>proc_macro_data</code> be <code>Some</code>, but <code>raw_proc_macros</code> be <code>None</code>: <a href="https://github.com/rust-lang/rust/blob/508b328c398b84126011f6fe74d018fe855bc242/compiler/rustc_metadata/src/creader.rs#L418">https://github.com/rust-lang/rust/blob/508b328c398b84126011f6fe74d018fe855bc242/compiler/rustc_metadata/src/creader.rs#L418</a></p>



<a name="248725777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/%27rustc%27%20panicked%20at%20%27called%20Option%3A%3Aunwrap%28%29%20on%20a%20None%20value/near/248725777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/&#x27;rustc&#x27;.20panicked.20at.20&#x27;called.20Option.3A.3Aunwrap().20on.20a.20None.20value.html#248725777">(Aug 07 2021 at 17:10)</a>:</h4>
<p>Probably. That was why I suggested <code>readelf --hexdump .rustc</code> to see if the metadata is different.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>